﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Objects;
using CodeFirstMembershipSharp;

namespace Project3.Models
{
    public class MeetingsRepository
    {
        private DataContext db = new DataContext();

        // Queries
        public IEnumerable<Meeting> FindAllMeetings()
        {
            return db.Meetings;
        }

        public IEnumerable<Meeting> FindUpcomingMeetings()
        {
            return db.Meetings.Where(q => q.When > DateTime.Now).OrderBy(q => q.When);
        }

        public Meeting GetMeeting(int id)
        {
            return db.Meetings.SingleOrDefault(d => d.MeetingID == id);
        }

        // Insert
        public void Add(Meeting meeting)
        {
            db.Meetings.Add(meeting);
        }

        // Delete
        public void Delete(int id)
        {
            db.Meetings.Remove(GetMeeting(id));
            Save();
        }

        // Save
        public void Save()
        {
            db.SaveChanges();
        }
    }
}